package edu.isistan.matching.utils.serviceMatching;

import iglu.ir.TermVector;

import java.util.StringTokenizer;
import java.util.Vector;

import edu.isistan.textmining.CaseChanger;
import edu.isistan.textmining.ComposedPreprocessor;
import edu.isistan.textmining.ContentPreprocessor;
import edu.isistan.textmining.DelimiterPreprocessor;
import edu.isistan.textmining.NameSplitterPreprocessor;
import edu.isistan.textmining.StopwordsPreprocessor;


public class SemanticPreprocessor{

	
	private ContentPreprocessor naturalLenguagePreprocessor = null;
	
	public SemanticPreprocessor(){
		Vector<ContentPreprocessor> filters = new Vector<ContentPreprocessor>(5);
		filters.add(new DelimiterPreprocessor());
		filters.add(new NameSplitterPreprocessor());
		filters.add(new CaseChanger());
		filters.add(new StopwordsPreprocessor());
		setNaturalLenguagePreprocessor(new ComposedPreprocessor(filters));
	}
	
	public TermVector preprocess(String naturalLanguageDesc) {				
        String preprocessed = getNaturalLenguagePreprocessor().getContent(naturalLanguageDesc );
        TermVector r = new TermVector();
        StringTokenizer st = new StringTokenizer(preprocessed);
        while (st.hasMoreTokens()) {
        	r.increment(st.nextToken());			
		}
        return r;
	}

	public ContentPreprocessor getNaturalLenguagePreprocessor() {
		return naturalLenguagePreprocessor;
	}

	public void setNaturalLenguagePreprocessor(ContentPreprocessor naturalLenguagePreprocessor) {
		this.naturalLenguagePreprocessor = naturalLenguagePreprocessor;
	}
}
